package leecode

import "strings"

func shortestSubstrings(arr []string) []string {
	ans := make([]string, len(arr))
	for i, s := range arr {
		res := ""
		for size := 1; size <= len(s) && res == ""; size++ {
		next:
			for k := size; k <= len(s); k++ {
				temp := s[k-size : k]
				if res != "" && temp >= res {
					continue
				}
				for j, t := range arr {
					if j != i && strings.Contains(t, temp) {
						continue next
					}
				}
				res = temp
			}
		}
		ans[i] = res
	}
	return ans
}
